package com.animee.health.utils;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.animee.health.bean.FoodBean;

import java.util.ArrayList;
import java.util.List;

public class DBTools {

    public DBTools() {
    }


    //插入
    public void insert(SQLiteDatabase readableDatabase, String title, String notmatch, String description, String picId) {
        ContentValues values = new ContentValues();
        values.put("title", title);
        values.put("notmatch", notmatch);
        values.put("description", description);
        values.put("picId", picId);

        readableDatabase.insert("Data", null, values);
    }

    public List<FoodBean> select(SQLiteDatabase readableDatabase) {
        List<FoodBean> list = new ArrayList<>();
        Cursor cursor = readableDatabase.query("Data", null, null, null, null, null, null);
        if (cursor.moveToFirst()) {
            do {
                String title = cursor.getString(cursor.getColumnIndex("title"));
                String notmatch = cursor.getString(cursor.getColumnIndex("notmatch"));
                String description = cursor.getString(cursor.getColumnIndex("description"));
                String picId = cursor.getString(cursor.getColumnIndex("picId"));
                list.add(new FoodBean(title, notmatch, description, Integer.parseInt(picId)));
            } while (cursor.moveToNext());
        }
        // for (FoodBean foodBean : list) {
        //     System.out.println("^^^^^^^^^^^^^^^^^^^^^^^foodBean = " + foodBean);
        // }
        return list;
    }
}
